<template>
	<view class="container" >
		<view class="cu-card">
			<view class="reg_box">
				<view class="cu-form-group margin-lr-lg border-b-line padding-0">
					<view class="title">请输入绑定手机号</view>
					<input data-key="phone" focus placeholder="请输入" v-model="phone" />
				</view>
				<view class="cu-form-group margin-lr-lg border-b-line padding-0">
					<view class="title">请输入验证码</view>
					<input data-key="smscode"  placeholder="验证码" v-model="code" />
					<button class="cu-btn line" style="color:#508ffd;border:1px solid #508ffd;" @click="getCode">{{message}}</button>
				</view>				
				<view class="cu-form-group margin-lr-lg border-b-line padding-0">
					<view class="title">设置新密码</view>
					<input data-key="password" password  placeholder="请输入" v-model="password" />
				</view>
				<view class="cu-form-group margin-lr-lg border-b-line padding-0">
					<view class="title">再次输入新密码</view>
					<input data-key="repassword" password  placeholder="请输入" v-model="repassword" />
				</view>
				<view class="cu-form-group margin-lr-lg border-b-line padding-0">
					<view class="title">支付密码</view>
					<input data-key="paypwd" password  placeholder="输入6位数字密码" v-model="paypwd" maxlength="6" />
				</view>
				<view class="cu-form-group margin-lr-lg  padding-0">
					<view class="title">重复密码</view>
					<input data-key="repaypwd" password  placeholder="重复6位数字密码" v-model="repaypwd" maxlength="6"/>
				</view>				
			</view>
			<view class="cu-form-group margin-lr-lg padding-0 submit_btn">
				<button class="cu_btn" type="button" @click="doreset">确认修改</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				index: 0,
				phone: "",
				code:"",
				password:"",
				repassword:"",
				paypwd:"",
				repaypwd:"",
				message: "获取验证码",
				uniqid:"",
				time: this.helper.time
			};
		},
		methods: {
			daojishi() {
				let eventinterval = setInterval(() => {
					this.message = this.time-- + "秒";
					if (this.time <= 0) {
						clearInterval(eventinterval);
						this.message = "发送验证码";
					}
				}, 1000);
			},
			getCode() {
				
				if(this.phone == ''){
					uni.showToast({
						title:"请输入手机号",
						icon:"none"
					})
					return;
				}
				if (this.message != "获取验证码") {
					return;
				}
				//短信验证码的获取
				let timestamp = this.helper.now();
				let sign = this.helper.setSign(["phone=" + this.phone, "type=repasswd","timestamp=" + timestamp]);
				this.helper.req({
					api:"getcode",
					timestamp:timestamp,
					data:{
						phone: this.phone,
						type:'repasswd'
					},
					header:{
						sign: sign
					}
				}).then(res=>{
					if (this.message == "获取验证码") {
						this.uniqid= res.data.data.uniqid;
						this.time = this.helper.time;
						this.daojishi();
					}
				});
			},
			doreset() {
				if(this.phone == ''){
					uni.showToast({
						title:"请输入手机号",
						icon:"none"
					})
					return;
				}
				if(this.password == ''){
					uni.showToast({
						title:"请输入密码",
						icon:"none"
					})
					return;
				}
				if(this.repassword == ''){
					uni.showToast({
						title:"请输入确认密码",
						icon:"none"
					})
					return;
				}
				if(this.code == ''){
					uni.showToast({
						title:"请输入验证码",
						icon:"none"
					})
					return;
				}
				let timestamp = this.helper.now();
				let sign = this.helper.setSign(['username='+this.phone,'uniqid='+this.uniqid,'code='+this.code,'password='+this.password,'repassword='+this.repassword,'paypwd='+this.paypwd,'repaypwd='+this.repaypwd,'timestamp='+timestamp]);
				this.helper.req({
					api:"reset",
					timestamp:timestamp,
					data:{username:this.phone,uniqid:this.uniqid,code:this.code,password:this.password,repassword:this.repassword,paypwd:this.paypwd,repaypwd:this.repaypwd},
					header:{
						sign: sign
					}
				}).then(res=>{
					//密码重置成功
					uni.showToast({
						title: "密码重置成功",
						icon: "none",
						position: "bottom",
						success: () => {
							setTimeout(()=>{
								uni.navigateTo({
									url:"../login/login"
								});
							},1000)
						}
					})
				});
			},
			// 链接
			navToUrl:function(url){
				uni.navigateTo({
					url: url,
				});	
			},
		}
	}
</script>

<style lang="scss">
	page {
		color: #56595d;
		background-color: #ddeafd;
	}
	.reset_title{
		font-size: 50upx;
		padding: 20upx;
	}
	.cu-form-group{
		background: none;
		height: 60px;
		
		input{
			color:#56595d;
			text-align: right;
		}
	}
	.cu-form-group .title {
		min-width: 200upx;
		color: #56595d;
	}
	.logo{
		padding: 80px 0 50px;
		text-align: center;
		image{
			width: 100px;
			height: 100px;
		}
	}
	.lg_img{
		width: 24px;
		height: 24px;
	}
	.reg_box{
		margin: 6vw 3vw;
		padding: 8px 0;
	  background: #ffffff;
		border-radius: 20rpx;
		position: relative;
	}
	.cu_btn{
		background: linear-gradient( 180deg, #9dc1ff 0%, #508ffd 100%);
		height: 50px;
		width: 70vw;
		color: #fff;
		line-height: 50px;
		font-size: 16px;
		border-radius: 30px;
	}
</style>
